#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math

print(abs(-100), max(10, 2, 31, 10.222, 556.5), hex(2555))


def sum(min, max):
    if not isinstance(min, (int, float)):  # 数据类型检查函数 isinstance
        raise TypeError("参数类型错误")
    if not isinstance(max, (int, float)):
        raise TypeError("参数类型错误")
    sum = 0
    while min <= max:
        sum += min
        min += 1
    return sum


print(sum(1, 2000))

# 返回多个值 是个tuple


def move(x, y, step, angle=0):  # 默认参数 不能为可变参数 定义时已经确定
    x_after = x + math.cos(angle) * step
    y_after = y - math.sin(angle) * step
    return x_after, y_after


print(move(100, 100, 60, math.pi / 6))

# 练习


def funcAns(a, b, c):
    if not isinstance(a, (int, float)):
        raise TypeError("参数类型错误")
    if not isinstance(b, (int, float)):
        raise TypeError("参数类型错误")
    if not isinstance(c, (int, float)):
        raise TypeError("参数类型错误")
    if a == 0:
        raise TypeError("参数错误")
    ans1 = (-b + math.sqrt(b * b - 4 * a * c)) / (2 * a)
    ans2 = (-b - math.sqrt(b * b - 4 * a * c)) / (2 * a)
    return ans1, ans2


print(funcAns(1, 3, -4))


# 可变参数
def sum2(*numbers):
    sum = 0
    for x in numbers:
        sum += x
    return sum


print(sum2(1, 2, 3, 4))
print(sum2(*[1, 2, 3, 4]))  # list或tuple加*直接作为可变参数


# 关键字参数 dict参数
def person(name, age, **other):
    print("name:", name, "age:", age, "other:", other)


person("dean", 26, **{"school": "111"})
person("dean", 26, school="1111", className="222")


# 命名关键字参数 即为关键字参数进行限制
def person2(name, age, *, city="nj", school):
    print(name, age, city, school)


person2("dean", 26, **{"school": 'sss'})

# 任意函数，都可以通过fun(*args, **args2)来调用


# 递归函数 尾递归（python未做优化）
def fact(num, product=1):
    if num == 1:
        return product
    return fact(num - 1, product * num)


print(fact(100))

# 函数练习  汉诺塔问题


def move2(n, a="A", b="B", c="C"):
    if n == 1:
        print(a + "=>" + c)
    else:
        move2(n - 1, a, c, b)
        move2(1, a, b, c)
        move2(n - 1, b, a, c)
# move2(10)
